package Wormish.agiletre.se.Math;


public class Mat22f {

	//Variables
	private float e11,e12,e21,e22;
	
	// --- Constructors
	public Mat22f(){
		e11 = 0.0f;
		e12 = 0.0f;
		e21 = 0.0f;
		e22 = 0.0f;
	}
	
	public Mat22f(float e11New, float e12New,float e21New, float e22New){
		this.setValues(e11New,e12New,e21New,e22New);
	}
	
	public Mat22f(Mat22f mat){
		e11 = mat.get11();
		e12 = mat.get12();
		e21 = mat.get21();
		e22 = mat.get22();
	}
	// --- End of constructors
	
	// --- Get methods
	public float get11(){
		return e11;
	}
	
	public float get12(){
		return e12;
	}
	
	public float get21(){
		return e21;
	}
	
	public float get22(){
		return e22;
	}
	// --- End of Get methods
	
	// --- Set methods
	public void set11(float e11New){
		e11 = e11New;
	}
	
	public void set12(float e12New){
		e12 = e12New;
	}
	
	public void set21(float e21New){
		e21 = e21New;
	}
	
	public void set22(float e22New){
		e22 = e22New;
	}
	
	public void setValues(float e11New, float e12New,float e21New, float e22New){
		e11 = e11New;
		e12 = e12New;
		e21 = e21New;
		e22 = e22New;
	}
	// --- End of Set methods
	
	// --- Linear algebra: Add
	public void add(Mat22f mat){
		e11 += mat.get11();
		e12 += mat.get12();
		e21 += mat.get21();
		e22 += mat.get22();

	}
	
	public void add(float e11Add, float e12Add, float e21Add, float e22Add){
		e11 += e11Add;
		e12 += e12Add;
		e21 += e21Add;
		e22 += e22Add;
	}
	
	public Mat22f add(Mat22f mat, boolean createNewMatrix){
		if (createNewMatrix){
			return new Mat22f(e11+mat.get11(),e12+mat.get12(),e21+mat.get21(),e22+mat.get22());
		}
		else{
			this.add(mat);
			return null;
		}
	}
	
	public Mat22f add(float e11Add, float e12Add, float e21Add, float e22Add, boolean createNewMatrix){
		if (createNewMatrix){		
			return new Mat22f(e11+e11Add,e12+e12Add,e21+e21Add,e22+e22Add);
		}
		else{
			this.add(e11Add, e12Add, e21Add, e22Add);
			return null;
		}
	}
	// --- End of Linear algebra: Add
	
	// --- Linear algebra: Subtract
	public void subtract(Mat22f mat){
		e11 -= mat.get11();
		e12 -= mat.get12();
		e21 -= mat.get21();
		e22 -= mat.get22();
		
	}
	
	public void subtract(float e11Sub, float e12Sub, float e21Sub, float e22Sub){
		e11 -= e11Sub;
		e12 -= e12Sub;
		e21 -= e21Sub;
		e22 -= e22Sub;
	}
	
	public Mat22f subtract(Mat22f mat, boolean createNewMatrix){
		if (createNewMatrix){
			return new Mat22f(e11-mat.get11(),e12-mat.get12(),e21-mat.get21(),e22-mat.get22());
		}
		else{
			this.subtract(mat);
			return null;
		}
	}
	
	public Mat22f subtract(float e11Sub, float e12Sub, float e21Sub, float e22Sub, boolean createNewMatrix){
		if (createNewMatrix){		
			return new Mat22f(e11-e11Sub,e12-e12Sub,e21-e21Sub,e22-e22Sub);
		}
		else{
			this.subtract(e11Sub, e12Sub, e21Sub, e22Sub);
			return null;
		}
	}
	// --- End of Linear algebra: Subtract
	
	// --- Linear algebra: Matrix multiplication
	public void mult(Mat22f mat){
		e11 = e11*mat.get11()+e12*mat.get21();
		e12 = e11*mat.get12()+e12*mat.get22();
		e21 = e21*mat.get11()+e22*mat.get21();
		e22 = e21*mat.get12()+e22*mat.get22();
	}
	
	public void mult(float e11Mult, float e12Mult, float e21Mult, float e22Mult){
		e11 = e11*e11Mult+e12*e21Mult;
		e12 = e11*e12Mult+e12*e22Mult;
		e21 = e21*e11Mult+e22*e21Mult;
		e22 = e21*e12Mult+e22*e22Mult;
	}
	
	public Mat22f mult(Mat22f mat, boolean createNewMatrix){
		if (createNewMatrix){
			return new Mat22f(e11*mat.get11()+e12*mat.get21(),e11*mat.get12()+e12*mat.get22(),e21*mat.get11()+e22*mat.get21(),e21*mat.get12()+e22*mat.get22());
		}
		else{
			this.mult(mat);
			return null;
		}
	}
	
	public Mat22f mult(float e11Mult, float e12Mult, float e21Mult, float e22Mult, boolean createNewMatrix){
		if (createNewMatrix){		
			return new Mat22f(e11*e11Mult+e12*e21Mult,e11*e12Mult+e12*e22Mult,e21*e11Mult+e22*e21Mult,e21*e12Mult+e22*e22Mult);
		}
		else{
			this.mult(e11Mult, e12Mult, e21Mult, e22Mult);
			return null;
		}
	}
	// --- End of Linear algebra: Matrix multiplication
	
	// --- Linear algebra: Vector multiplication
	public void mult(Vec2f vec){
		float x = vec.getX();
		float y = vec.getY();
		vec.setX(e11*x+e12*y);
		vec.setY(e21*x+e22*y);
	}
	
	public Vec2f mult(Vec2f vec, boolean createNewVector){
		if (createNewVector){
			return new Vec2f(e11*vec.getX()+e12*vec.getY(),e21*vec.getX()+e22*vec.getY());
		}
		else{
			this.mult(vec);
			return null;
		}
	}
	// --- End of Linear algebra: Vector multiplication
}